import {Component, Input, OnInit} from '@angular/core';
import {CoffeIncoming} from '../../../../model/CoffeIncoming';
import {NzModalRef} from 'ng-zorro-antd/modal';
import {AlertService} from "../../../../services/alert.service";
import {AdminService} from "../../../../services/admin.service";
import {AuthService} from "../../../../services/auth.service";

@Component({
  selector: 'app-coffeeincomedit',
  templateUrl: './coffeeincomedit.component.html',
  styleUrls: ['./coffeeincomedit.component.css']
})
export class CoffeeincomeditComponent implements OnInit {
  @Input() optype: string
  @Input() id: string
  c: CoffeIncoming;
  PmArray: Array<any>;
  GysArray: Array<any>;
  CgArray: Array<any>;



  constructor(private modal: NzModalRef, private adminService: AdminService, private alertService: AlertService,
              private authService:AuthService) {
    this.c = new CoffeIncoming();
    this.PmArray = new Array()
    this.GysArray = new Array()
    this.CgArray = new Array()


  }

  ngOnInit(): void {
    this.getPmArray();
    this.getCgArray();


    this.getGysArray();

    if (this.optype == "update") {
      this.getCoffeeincomingByid()
    }
  }

  getCoffeeincomingByid() {
    this.adminService.getCoffeeincomingByid(this.id).then((data: any) => {
      if (data.msg == "ok") {
        this.c = data.obj
      } else {
        this.alertService.showSuccess("根据id获取咖啡入库失败")
      }
    })
  }

  save() {
    this.adminService.saveCoffeeincoming(this.c).then((data: any) => {
      if (data.msg == "ok") {
        this.alertService.showSuccess("设置咖啡入库成功")
      } else {
        this.alertService.showSuccess("设置咖啡入库失败")
      }
    })
  }

  getPmArray() {
   this.adminService.getNzSelCateByTypeid("d92b86068b2f4796960c685a7ff91c3e").then((data:any)=>{
     if(data.msg == "ok"){
       this.PmArray = data.list
     }else{
       this.alertService.showError("获取品名数组失败")
     }
   })
  }
  getCgArray() {
      this.authService.getMemberListByRole("11988d2da3984556b02266ca1bdf14f8").then((data:any)=>{
        if(data.msg == "ok"){
          this.CgArray = data.list
        }else{
          this.alertService.showError("获取采购人员数组失败")
        }
      })
  }

  getGysArray() {
   this.adminService.getGysSel().then((data:any)=>{
     if(data.msg == "ok"){
       this.GysArray = data.list
     }else{
       this.alertService.showError("获取供应商数组失败")
     }
   })
  }
}
